package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.view.View;

import com.qo.qsdk.model.UserModel;
import com.qo.qsdk.ui.QSDKListener;
import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;
import com.qo.qsdk.utils.QSDKHelper;

public class BindView implements IBaseView{

    private QTextView mTitle, mAccount, mChange;
    private QBTextView mBtn;
    private QTextView mAccountL, mAccountR, mFbL, mFbR, mGoogleL, mGoogleR, mDesc, mAppleL, mAppleR;
    private View mMain, mBindA, mBindFb, mBindGP, mBindApple;
    private Activity mActivity;
    private QSDKListener mQSDKListener;

    public BindView(Activity mActivity, QSDKListener iAccountListener) {
        this.mActivity = mActivity;
        this.mQSDKListener = iAccountListener;
        init(mActivity);
    }

    private void init(Activity v) {
        mMain = v.findViewById(DynamicUtils.id(mActivity, "mainBind"));
        mMain.setVisibility(View.GONE);
        mTitle = v.findViewById(DynamicUtils.id(mActivity, "bindTitle"));
        mAccount = v.findViewById(DynamicUtils.id(mActivity, "bindAccount"));
        mChange = v.findViewById(DynamicUtils.id(mActivity, "bindChange"));
        mBtn = v.findViewById(DynamicUtils.id(mActivity, "bindBtn"));

        mAccountL = v.findViewById(DynamicUtils.id(mActivity, "bindAccountL"));
        mAccountR = v.findViewById(DynamicUtils.id(mActivity, "bindAccountR"));
        mFbL = v.findViewById(DynamicUtils.id(mActivity, "bindFbL"));
        mFbR = v.findViewById(DynamicUtils.id(mActivity, "bindFbR"));
        mGoogleL = v.findViewById(DynamicUtils.id(mActivity, "bindGoogleL"));
        mGoogleR = v.findViewById(DynamicUtils.id(mActivity, "bindGoogleR"));
        mAppleL = v.findViewById(DynamicUtils.id(mActivity, "bindAppleL"));
        mAppleR = v.findViewById(DynamicUtils.id(mActivity, "bindAppleR"));
        mDesc = v.findViewById(DynamicUtils.id(mActivity, "bindDesc"));
        mMain.setVisibility(View.GONE);

        v.findViewById(DynamicUtils.id(mActivity, "bindA")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindAccount(mGuestModel);
            }
        });
        v.findViewById(DynamicUtils.id(mActivity, "bindFb")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindFb(mGuestModel);
            }
        });
        v.findViewById(DynamicUtils.id(mActivity, "bindGoogle")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindGoogle(mGuestModel);
            }
        });
        v.findViewById(DynamicUtils.id(mActivity, "bindApple")).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindApple(mGuestModel);
            }
        });
        mChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindChange();
            }
        });
        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mQSDKListener != null) mQSDKListener.onBindContinue(isFromGuestLogin,mGuestModel);
            }
        });
    }

    public void show(Activity activity) {
        refresh();
        mMain.setVisibility(View.VISIBLE);
    }

    public void setUserModel(UserModel userModel) {
        isFromGuestLogin = false;
        mGuestModel = userModel;
        mAccount.setText(userModel.getAccount());
    }

    private boolean isFromGuestLogin;
    private UserModel mGuestModel;
    public void setUserModelWithGuest(UserModel userModel) {
        isFromGuestLogin = true;
        mGuestModel = userModel;
        mAccount.setText(userModel.getAccount());
    }

    public void hide(Activity activity) {
        mMain.setVisibility(View.GONE);
    }

    public void refresh() {
        mTitle.setText(Language.Bind_Title.toString());

        mChange.setText(Language.Bind_Change.toString());
        mBtn.setText(Language.Bind_Btn.toString());

        mAccountL.setText(Language.Bind_Row1_L.toString());
        mAccountR.setText(Language.Bind_Row1_R.toString());
        mFbL.setText(Language.Bind_Row2_L.toString());
        mFbR.setText(Language.Bind_Row2_R.toString());
        mGoogleL.setText(Language.Bind_Row3_L.toString());
        mGoogleR.setText(Language.Bind_Row3_R.toString());
        mAppleL.setText(Language.Bind_Row4_L.toString());
        mAppleR.setText(Language.Bind_Row4_R.toString());

        mDesc.setText(Language.Bind_Desc.toString());
    }
}
